﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Infrastructure.ViewModels;
using Infrastructure.CurrentData;
using DataStore;
using DataStore.Repositories;
using DataStore.Domain;
using Infrastructure;

namespace UI.Dialogs
{
    /// <summary>
    /// Interaction logic for Author.xaml
    /// </summary>
    public partial class AuthorForm : Window
    {

        private AuthorViewModel _author;
        public AuthorViewModel Author
        {
            get
            {
                return _author;
            }
            set
            {
                _author = value;
                DataContext = _author;
                okCancel.OkButton.Command = _author.SaveCommand;
            }
        }

        public AuthorForm()
        {
            InitializeComponent();
            Author = new AuthorViewModel(new DataStore.Domain.Author());
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Author.Emails.Add(new EmailLinkViewModel(new EmailLink()));
            var row = Emails.GetRow(Author.Emails.Count - 1);
            var cell = Emails.GetCell(row, 0);
            Emails.UnselectAll();
            Emails.EditCell(cell);
        }

        private void okCancel_CancelClicked(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        private void okCancel_OkClicked(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }
    }
}
